package com.openbravo.pos.inventory;

import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import javax.swing.JTabbedPane;

import cn.ekuma.data.dao.ChildEditorRecord;
import cn.ekuma.data.dao.I_ParentNode;
import cn.ekuma.data.ui.swing.ParentNodeChangeListener;
import cn.ekuma.epos.datalogic.I_DataLogicSales;

import com.openbravo.bean.Location;
import com.openbravo.bean.LocationLayout;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.gui.ComboBoxValModel;
import com.openbravo.data.gui.MessageInf;
import com.openbravo.data.user.DirtyManager;
import com.openbravo.pos.base.AppLocal;
import com.openbravo.pos.base.AppView;

public class JLocationLayoutEditor extends BaseCategoriesEditor<LocationLayout> implements ChildEditorRecord<LocationLayout>,ParentNodeChangeListener<String>{

	protected I_ParentNode<String> parentNode;
    protected int parentState;
	
	public JLocationLayoutEditor(AppView app, DirtyManager dirty,
			boolean showButtom,I_DataLogicSales dlSales) {
		super(app, dirty, showButtom, dlSales);
		
	}

	@Override
	public void addChildTabPanel(JTabbedPane tabbedPane) {	
		
	}
	
	public void refresh() {      
        List a;       
        try {
            a = dlSales.list(getEditClass(),Location.class,parentNode.getParentKey().getKey());
        } catch (BasicException eD) {
            MessageInf msg = new MessageInf(MessageInf.SGN_NOTICE, AppLocal.getIntString("message.cannotloadlists"), eD);
            msg.show(this);
            a = new ArrayList();
        } 
        a.add(0, null); // The null item
        m_CategoryModel = new ComboBoxValModel(a);
        m_jCategory.setModel(m_CategoryModel);
    }
	
	@Override
	public LocationLayout createNew(Properties prop) {
		LocationLayout obj=new LocationLayout();
		obj.setLocationId(parentNode.getParentKey().getKey());
		return obj;
	}

	@Override
	public Class getEditClass() {
		return LocationLayout.class;
	}

	    public I_ParentNode<String> getParentNode() {
	        return parentNode;
	    }

	    public void parentNodeValueChange(int state, I_ParentNode<String> parent) {
	        this.parentState=state;
	        this.parentNode=parent;
	        if(state==this.STATE_Edit)
	        	this.refresh();
	    }
	    
	    public void setParentNode(I_ParentNode<String> parentNode) {
	        this.parentNode = parentNode;
	    }

	    public int getParentState() {
	        return parentState;
	    }

	    public void setParentState(int parentState) {
	        this.parentState = parentState;
	    }

		@Override
		public String getTabName() {
			return "locationLayout";
		}
	
		
		
}
